<?php
namespace app\api\controller\com;
use x\my\jssdk\jssdk;

class Com extends Base {
	//获取配置
	public function getsys() {
		$d = $this->post;
		if (!isset($d['config_key'])) {
			err('请输入config_key');
		}
		$key = explode(",", $d['config_key']);
		$rs = [];
		foreach ($key as $v) {
			$rs[$v] = c("{$d['config_key']}");
		}
		return suc($rs);
	}

	//获取配置
	public function deploy() {
		$d = $this->post;
		if (!isset($d['uuid'])) {
			err('请输入key');
		}
		$key = explode(",", $d['uuid']);
		$rs = [];
		foreach ($key as $v) {
			$rs[$v] = $this->sys[$v];
		}
		return suc($rs);
	}

	public function getinfo() {
		$d = $this->post;
		$rule = [
			'token' => 'require',
		];
		$msg = [];
		check($rule, $msg, $d);
		$userinfo = $this->db->query("select * from user where wap_token=?", [$d['token']], 1);
		suc($userinfo);
	}

	//
	public function getWord() {
		$d = $this->post;
		$uuid = $d['uuid'];
		if (!empty($uuid)) {
			$word = $this->db->query("select * from word where uuid = ?", [$uuid], 1);
			if ($word) {
				$word['h5_url'] = url('h5/getword', ['id' => $word['id']]);
			}

		} else {
			$word = $this->db->query("select * from word");
			foreach ($word as $key => $val) {
				$val['h5_url'] = url('h5/getword', ['id' => $val['id']]);
				$word[$val['uuid']] = $val;
				unset($word[$key]);
			}
		}
		suc($word);
	}
	public function getImg() {
		$d = $this->post;
		$id = $d['id'];
		$img = $this->db->query("select * from img where id = ?", [$id], 1);
		suc($img);
	}
	//获取子地区名称
	public function getComAddress() {
		$d = $this->post;
		$pid = $d['pid'];
		if ($pid == '') {
			$rs = $this->db->query('select id,name,parent_id from com_address');
		} else {
			$rs = $this->db->query('select id,name,parent_id from com_address where parent_id=?', [$pid]);
		}
		suc($rs);
	}

	//获取银行卡信息
	public function getComBank() {
		$d = $this->post;
		$rs = $this->db->query('select * from com_bank');
		suc($rs);
	}

	//获取微信配置
	public function getWeixinConfig() {
		$jssdk = new jssdk(c('api.wx_gzh_appid'), c('api.wx_gzh_appsecret'));
		suc($jssdk->getSignPackage());
	}

}
